package update_history_editor_material_audit_data

import (
	syncCmd "cid-media-api/workers/data/sync-director-material-audit-data"
	"github.com/robfig/cron/v3"
	"log"
	"os"
	"time"
)

func Run(cronSpec string) {
	c := cron.New()
	c.AddFunc(cronSpec, func() {
		logFile, err := os.OpenFile("/www/logs/cid-media-api/crontab/update_history_director_material_audit_data_"+time.Now().Format(time.DateOnly)+".log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
		if err != nil {
			log.Fatal(err)
		}
		defer logFile.Close()

		logger := log.New(logFile, "", log.LstdFlags)
		// 更新脚本默认跑2025-01-01到6天前的数据
		endDate := time.Now().AddDate(0, 0, -5).Format(time.DateOnly)
		startDate := "2025-01-01"
		syncCmd.Execute(startDate, endDate, logger)
	})

	c.Run()
}
